/*******************************************************************************
02_02: Make Table 2: Regression-adjusted relationship between non-market work and immigrant generation

Replication code for "Culture and gender allocation of tasks: source country 
	characteristics and the division of non-market work among US immigrants" in
	Review of Economics of the Household

Authors: Francine Blau, Lawrence Kahn, Matthew Comey, Amanda Eng, Pamela 
	Meyerhofer, and Alexander Willen
	
Date: 10/16/2020

Description: This code generates Table 2

*******************************************************************************/


/*******************************************************************************

I. Preliminaries

*******************************************************************************/

***A. Erase existing output if necessary
cap erase "$tables/Table_2_Panel_A.xls"
cap erase "$tables/Table_2_Panel_A.txt"
cap erase "$tables/Table_2_Panel_B.xls"
cap erase "$tables/Table_2_Panel_B.txt"
cap erase "$tables/Table_2_Panel_C.xls"
cap erase "$tables/Table_2_Panel_C.txt"
cap erase "$tables/Table_2_Panel_D.xls"
cap erase "$tables/Table_2_Panel_D.txt"

***B. Set control variables
local controls age age2 RACE2 RACE3 RACE4 RACE5 

local fe i.day i.month i.year i.state

local ecp_controls hsdi scol cold young_children middle_children old_children part_age part_age2 part_hsdi part_scol part_cold part_RACE2 part_RACE3 part_RACE4 part_RACE5

local wife_work wifehours wifehours_vary

 
/*******************************************************************************

II. Run Regressions

*******************************************************************************/

local maintit  "Table 2: Regression-adjusted relationship between non-market work and immigrant generation"

**Loop through table panels
foreach panel in A B C D {
	
	*Set sample restrictions and labels
	preserve
	
	if "`panel'" == "A" {
	    di "*****Regressing for All Women*****"
		
		keep if female == 1
		
		local tabtit "`maintit', Panel A. All Women"
		}
	else if "`panel'" == "B" {
	    di "*****Regressing for Women with Children*****"
		
		drop if hh_numownkids== 0
		keep if youngc<18 
		keep if female == 1
		
		local tabtit "`maintit', Panel B. Women with Children"
		}
	else if "`panel'" == "C" {
	    di "*****Regressing for All Men*****"
		
		keep if female == 0
		
		local tabtit "`maintit', Panel C. All Men"
		}
	else if "`panel'" == "D" {
	    di "*****Regressing for Men with Children*****"
		
		drop if hh_numownkids== 0
		keep if youngc<18 
		keep if female == 0
		
		local tabtit "`maintit', Panel D. Men with Children"
		}

	**Loop through non-market work variables
	foreach var in $nmw $hwork $ccare { 
				
		if "`var'" == "$nmw" {
			local coltit "Total Non-Market Work"
			}
		else if "`var'" == "$hwork" {
			local coltit "Housework"
			}
		else if "`var'" == "$ccare" {
			local coltit "Childcare"
			}
			
		**Regress
		*baseline
		reg `var' immig secondgen `controls' `fe' [aw=newwt] 
			quietly summ `var' [aw=newwt]  if e(sample)==1
			outreg2 using "$tables/Table_2_Panel_`panel'.xls", keep(immig secondgen ) append ctitle(`coltit') addstat(Mean, r(mean)) addtext(Education Children and Spouse Controls, No, Wife's Market Work Controls, No) label title("`tabtit'") nocons

		*add education, children, and partner controls
		reg `var' immig secondgen `controls' `ecp_controls' `fe' [aw=newwt] 
			quietly summ `var' [aw=newwt]  if e(sample)==1   
			outreg2 using "$tables/Table_2_Panel_`panel'.xls", keep(immig secondgen ) append ctitle(`coltit') addstat(Mean, r(mean)) addtext(Education Children and Spouse Controls, Yes, Wife's Market Work Controls, No) label nocons
			
			
		*add wife's hours
		reg `var' immig secondgen `controls' `ecp_controls' `wife_work' `fe' [aw=newwt] 
			quietly summ `var' [aw=newwt]  if e(sample)==1   
			outreg2 using "$tables/Table_2_Panel_`panel'.xls", keep(immig secondgen ) append ctitle(`coltit') addstat(Mean, r(mean)) addtext(Education Children and Spouse Controls, Yes, Wife's Market Work Controls, Yes) label nocons
			
		}

	restore
	
}


***Erase text files
cap erase "$tables/Table_2_Panel_A.txt"
cap erase "$tables/Table_2_Panel_B.txt"
cap erase "$tables/Table_2_Panel_C.txt"
cap erase "$tables/Table_2_Panel_D.txt"
